package InterfaceGrafica;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.SlickException;

import ConexaoBanco.RepositorioEscapeBD;
import Jogo.Escape;
import Player.CadastroJogador;
public class RegistroJogador extends JFrame implements ActionListener{
	RepositorioEscapeBD bd = new RepositorioEscapeBD();

	JTextField nome = new JTextField(15);
	//JTextField info = new JTextField(55);
	JButton ok = new JButton("Ok");
	JButton cancel = new JButton("Cancelar");

	public RegistroJogador(){
		super("Registro de Jogador");
		setSize(383,120);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(false);



		JPanel panel = new JPanel();
		JLabel info = new JLabel("Digite seu nome para registrar sua pontuacao no Ranking");
		JLabel nomeLabel = new JLabel("Nome: ");
		ok.addActionListener(this);
		cancel.addActionListener(this);
		panel.add(info);
		panel.add(nomeLabel);
		panel.add(nome);
		panel.add(ok);
		panel.add(cancel);
		add(panel);
		setVisible(true);
		setBounds(400, 100, 382, 120);

	}

	@Override
	public void actionPerformed(ActionEvent evt) {

		Object source = evt.getSource();

		CadastroJogador cj = new CadastroJogador(nome.getText());

		AppGameContainer app = null;
		try {
			app = new AppGameContainer(new Escape());
		} catch (SlickException e) {

			e.printStackTrace();
		}


		if(source == cancel){
			MenuInicial mi = new MenuInicial();
			this.setVisible(false);
			mi.setVisible(true);

		}


		if (source == ok){
			bd.inserir(cj);
			this.setVisible(false);


			try {
				app.setDisplayMode(800, 600, false);
				app.start();

			} catch (SlickException e) {

				e.printStackTrace();
			}

		}
	}

}
